# -*- coding: utf-8 -*-
""" 
@author: ertao.xyz
@create: 2021-10-11 10:41
@description: 
"""
from typing import List
from enum import Enum

from tortoise import fields
from tortoise.models import Model
from tortoise.contrib.pydantic import pydantic_model_creator

from core.model import AbstractBaseModel, TimestampMixin


# class SettingType(str, Enum):
#     webSite = "webSite"
#     qiNiu = "qiNiu"
#     email = "email"
#
#     # qiNiuAccess = "qiNiuAccess" # 填你的access_key
#     # qiNiusecret = "qiNiusecret" # 填你的secret_key
#     # qiNiuDomain = "qiNiuDomain" # 填你的存储空间名称
#     # qiNiuBucketName = "qiNiuBucketName" # 填你的空间域名
#
#
# class Setting(TimestampMixin, Model):
#     key = fields.CharField(max_length=32)
#     type = fields.CharEnumField(SettingType)
#     value = fields.CharField(max_length=256, null=True, default=None)
#
#     class Meta:
#         table = 'setting'
#         table_description = '系统设置'
#         ordering = ["-key", "id"]
#         unique_together = ("type", "key")
#
#     class PydanticMeta:
#         exclude = ["created_at", "modified_at"]


class QiniuSetting(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    access_key = fields.CharField(max_length=128, null=True, default=None, description='access_key')
    secret_key = fields.CharField(max_length=128, null=True, default=None, description='secret_key')
    bucket_name = fields.CharField(max_length=128, null=True, default=None, description='空间名')
    domain = fields.CharField(max_length=128, null=True, default=None, description='域名')
    status = fields.BooleanField(default=True, description='是否启用')
    default = fields.BooleanField(default=False, description='是否默认')

    class Meta:
        table = 'qiniuSetting'
        table_description = '七牛设置'
        ordering = ["-created_at"]

    class PydanticMeta:
        exclude = ["created_at", "modified_at", 'default']


class EmailSetting(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    server = fields.CharField(max_length=128, null=True, default=None, description='SMTP服务器')
    port = fields.CharField(max_length=128, null=True, default=None, description='SMTP端口')
    send_email = fields.CharField(max_length=128, null=True, default=None, description='发信人地址')
    nickname = fields.CharField(max_length=128, null=True, default=None, description='发信人呢称')
    username = fields.CharField(max_length=128, null=True, default=None, description='邮箱登录用户名')
    password = fields.CharField(max_length=128, null=True, default=None, description='邮箱登录密码')
    status = fields.BooleanField(default=True, description='是否启用')
    default = fields.BooleanField(default=False, description='是否默认')

    class Meta:
        table = 'emailSetting'
        table_description = '邮箱设置'
        ordering = ["-created_at"]

    class PydanticMeta:
        exclude = ["created_at", "modified_at", 'default']


class BaseSetting(AbstractBaseModel, TimestampMixin):
    user = fields.OneToOneField('models.User', description='拥有者')
    email = fields.CharField(max_length=128, null=True, default=None, description='邮箱')
    # name = fields.CharField(max_length=128, null=True, default=None, description='昵称')
    introduction = fields.TextField(null=True, default=None, description='个人简介')
    # phone = fields.CharField(max_length=128, null=True, default=None, description='联系电话')
    address = fields.BooleanField(default=False, description='所在地区')

    class Meta:
        table = 'baseSetting'
        table_description = '基础设置'
        ordering = ["-created_at"]

    class PydanticMeta:
        exclude = ["created_at", "modified_at", 'default']
